<?php
    include '../connectDatabase.php';

    $ID = $_POST['ID'];
    $username = $_POST['username'];
    $passwd = $_POST['passwd'];
    $email = $_POST['email'];
    $sex = $_POST['sex'];
    $type = "管理员";

    if($username==null){
        $username = $ID;
    }

    $sql = "select * from users where user_id='$ID'";

    $result = mysqli_query($conn,$sql);
    $records = array();
    while($record = mysqli_fetch_array($result))
    {
        $records [] = $record;
    }


    if($records != null){
        echo "<script>alert('该管理员已存在！');window.location.href='http://localhost:8080/PHP-NEWS-RELEASE-SYSTEM/Application/User/Page/login.php'</script>";    
    }
    else {
        $sql1 = "INSERT INTO users (user_id,user_name, user_password,user_sex,user_type,user_email) VALUES ('$ID', '$username','$passwd','$sex','$type','$email' )";
        if (mysqli_query($conn, $sql1)) {
            echo "<script>alert('添加成功');window.location.href='http://localhost:8080/PHP-NEWS-RELEASE-SYSTEM/Application/User/Page/login.php'</script>";
        } else {
            echo "Error: " . $sql1 . "<br>" . mysqli_error($serverLink1);
        }
    }



?>